package com.jy.modules.cims.interact;

import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.common.CimsIrtUrlConstant;
import com.jy.modules.cims.common.exception.CimsExceptionConstant;
import com.jy.modules.cims.common.exception.InteractException;
import com.jy.modules.cims.data.dto.ApproveConfirmResultDto;
import com.jy.modules.cims.data.dto.ConfirmParamDto;
import com.jy.modules.cims.data.dto.QuotaApplyParamDto;
import com.jy.modules.cims.data.dto.QuotaApplyResultDto;
import com.jy.modules.cims.data.dto.QuotaDetailUnlockParamDto;
import com.jy.modules.cims.data.dto.QuotaDetailUnlockResultDto;
import com.jy.modules.cims.data.dto.QuotaReturnDto;
import com.jy.modules.cims.data.dto.credit.BatchCreditQueryDto;
import com.jy.modules.cims.data.dto.credit.BatchCreditQueryResultDto;
import com.jy.modules.cims.data.dto.credit.CreditRepayPlanQueryDto;
import com.jy.modules.cims.data.dto.credit.CreditRepayPlanQueryResultDto;
import com.jy.modules.cims.data.dto.credit.CreditValueCalculateDto;
import com.jy.modules.cims.data.dto.credit.CreditValueCalculateResultDto;
import com.jy.modules.cims.data.dto.credit.PublicInfoQueryDto;
import com.jy.modules.cims.data.dto.credit.PublicInfoQueryResult;
import com.jy.modules.cims.data.dto.credit.PublicSettleParamDto;
import com.jy.modules.cims.data.dto.credit.PublicSettleResultDto;
import com.jy.modules.cims.data.dto.credit.RedeemParamDto;
import com.jy.modules.cims.data.dto.credit.RedeemResultDto;
import com.jy.modules.cims.data.dto.loan.LoanDealSettleDto;
import com.jy.modules.cims.data.dto.loan.LoanFundOutDto;
import com.jy.modules.cims.data.dto.loan.LoanFundOutResultDto;
import com.jy.modules.cims.data.interact.core.CoreStatusResponse;
import com.jy.modules.cims.data.interact.core.credit.request.Request4029DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4036DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4029DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4036DTO;
import com.jy.modules.cims.data.interact.core.loan.response.ImgUrl;
import com.jy.modules.cims.data.interact.core.loan.response.LoanData;
import com.jy.modules.cims.data.interact.core.loan.response.Response8003DTO;
import com.jy.modules.cims.interact.util.FilterCreditDetailUtil;

/**
 * 
 * <b>类名称：</b>CCInteractImpl <br/>
 * <b>类描述：系统交互服务组件默认实现层</b><br/>
 * <b>创建人：</b>chenguixue<br/>
 * <b>修改人：</b><br/>
 * <b>修改时间：</b>2015-1-21 上午10:59:43<br/>
 * <b>修改备注：</b><br/>
 * <b>版本信息：</b>v1.0.0<br/>
 */
@Service("com.jy.modules.cims.interact.CCInteractImpl")
public class CCInteractImpl implements ICInteract {

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.CIRLoanIFImpl")
    private CIRLoanIFImpl loanIFImpl;

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.CIRCreditPoolIFImpl")
    private CIRCreditPoolIFImpl creditPoolIFImpl;
    
    @Autowired
    @Qualifier("com.jy.modules.cims.interact.CIRLoanSettleIFImpl")
    private CIRLoanSettleIFImpl loanSettleIFImpl;


    @Autowired
    @Qualifier("com.jy.modules.cims.interact.util.FilterCreditDetailUtil")
    private FilterCreditDetailUtil filterCreditDetailUtil;

    /**
     * 额度申请
     * 
     * @author chenguixue
     * @date 2015-1-23 下午4:47:44
     * @see com.jy.modules.cims.interact.ICInteract#quotaApply(com.jy.modules.cims.data.dto.QuotaApplyParamDto)
     */
    @Override
    public QuotaApplyResultDto quotaApply(QuotaApplyParamDto paramDto) {
        paramDto.setOperType(CimsIrtUrlConstant.IRT_QUOTAAPPLY_OPERTYPE_NEW); // //
                                                                              // 设置额度操作类型为新建
        if (CimsConstant.QUOTATYPE_LOAN.equals(paramDto.getQuotaType()))
            return loanIFImpl.quotaApply(paramDto);
        else if (CimsConstant.QUOTATYPE_CR.equals(paramDto.getQuotaType()))
            return creditPoolIFImpl.quotaApply(paramDto);
        throw new InteractException(CimsExceptionConstant.INTERACT_QUOTA_NOT_SET_TYPE);
    }

    /**
     * 额度取消
     * 
     * @author chenguixue
     * @date 2015-1-23 下午4:47:55
     * @see com.jy.modules.cims.interact.ICInteract#quotaCancel(com.jy.modules.cims.data.dto.QuotaApplyParamDto)
     */
    @Override
    public QuotaApplyResultDto quotaCancel(QuotaApplyParamDto paramDto) {
        paramDto.setOperType(CimsIrtUrlConstant.IRT_QUOTAAPPLY_OPERTYPE_CANCEL); // //
                                                                                 // 设置额度操作类型为取消

        if (CimsConstant.QUOTATYPE_LOAN.equals(paramDto.getQuotaType())) {
            return loanIFImpl.quotaApply(paramDto); // 贷款额度取消复用额度申请方法
        } else if (CimsConstant.QUOTATYPE_CR.equals(paramDto.getQuotaType())) {
            return creditPoolIFImpl.quotaCancel(paramDto);
        }
        throw new InteractException(CimsExceptionConstant.INTERACT_QUOTA_NOT_SET_TYPE);
    }

    /**
     * 异步获取额度申请结果
     * 
     * @author chenguixue
     * @date 2015-1-23 下午4:23:09
     * @see com.jy.modules.cims.interact.ICInteract#getQuotaLockResult(com.jy.modules.cims.data.dto.QuotaApplyParamDto)
     */
    @Override
    public QuotaApplyResultDto getQuotaApplyResult(QuotaApplyParamDto paramDto) {
        paramDto.setOperType(CimsIrtUrlConstant.IRT_QUOTAAPPLY_OPERTYPE_QUERY); // //
                                                                                // 设置额度操作类型为查询

        if (CimsConstant.QUOTATYPE_LOAN.equals(paramDto.getQuotaType())) {
            return loanIFImpl.getQuotaApplyResult(paramDto);
        } else if (CimsConstant.QUOTATYPE_CR.equals(paramDto.getQuotaType())) {
            return creditPoolIFImpl.getQuotaApplyResult(paramDto);
        }
        throw new InteractException(CimsExceptionConstant.INTERACT_QUOTA_NOT_SET_TYPE);
    }

    /**
     * 额度明细释放
     * 
     * @author chenguixue
     * @date 2015-1-23 下午4:48:09
     * @see com.jy.modules.cims.interact.ICInteract#quotaDetailUnlock(com.jy.modules.cims.data.dto.QuotaDetailUnlockParamDto)
     */
    @Override
    public QuotaDetailUnlockResultDto quotaDetailUnlock(QuotaDetailUnlockParamDto paramDto) {
    	filterCreditDetailUtil.filterCreditDetail(paramDto);
    	
        if (CimsConstant.QUOTATYPE_LOAN.equals(paramDto.getQuotaType()))
            return loanIFImpl.quotaDetailUnlock(paramDto);
        else if (CimsConstant.QUOTATYPE_CR.equals(paramDto.getQuotaType()))
            return creditPoolIFImpl.quotaDetailUnlock(paramDto);
        throw new InteractException(CimsExceptionConstant.INTERACT_QUOTA_NOT_SET_TYPE);
    }

    /**
     * 贷款、债权审批确认
     * @author chenguixue
     * @date 2015-1-21 上午10:51:27
     * @see com.jy.modules.cims.interact.ICInteract#loanApproveConfrim(com.jy.modules.cims.core.dto.LoanApproveConfirmParamDto)
     */
    @Override
    public ApproveConfirmResultDto approveConfrim(ConfirmParamDto approveDto) {
    	filterCreditDetailUtil.filterCreditDetail(approveDto);
    	
        if (CimsConstant.QUOTATYPE_LOAN.equals(approveDto.getBusiType())) {
            return loanIFImpl.loanApproveConfrim(approveDto);
        } else if (CimsConstant.QUOTATYPE_CR.equals(approveDto.getBusiType())) {
            return creditPoolIFImpl.confirmCreditRightTransfer(approveDto);
        }
        throw new InteractException(CimsExceptionConstant.INTERACT_QUOTA_NOT_SET_TYPE);
    }

    /**
     * 贷款放款确认
     * @author chenguixue
     * @date 2015-3-2 下午7:10:17
     * @see com.jy.modules.cims.interact.ICInteract#loanFundOut(com.jy.modules.cims.data.dto.loan.LoanFundOutDto)
     */
    @Override
    public LoanFundOutResultDto loanFundOut(LoanFundOutDto loanFundOutDto) {
        return loanIFImpl.loanFundOut(loanFundOutDto);
    }

    /**
     * 更新债权池状态
     * 
     * @param quotaBatchId
     * @param quotaList
     * @param Object>>
     * @return
     */
    public void refreshCreditListStatus(String quotaBatchId, List<Map<String, Object>> list) {

    }

    /**
     * 
     * @author chenguixue
     * @date 2015-3-3 上午10:37:36
     * @see com.jy.modules.cims.interact.ICInteract#getCreditDetail(com.jy.modules.cims.data.dto.credit.SingleCreditQueryDto)
     */
    public BatchCreditQueryResultDto getCreditDetail(BatchCreditQueryDto batchCreditQueryDto) {
    	filterCreditDetailUtil.filterCreditDetail(batchCreditQueryDto);
    	
        return creditPoolIFImpl.getCreditDetail(batchCreditQueryDto);
    }

    /**
     * 更新贷款状态信息
     * 
     * @param quotaBatchId
     * @param list
     */
    public void refreshLoanListStatus(String quotaBatchId, List<Map<String, Object>> list) {

    }

    /**
     * 根据指定类型获取还款计划
     * 
     * @param type 贷款、债权
     * @param list 贷款或债权编号列表
     * @return
     */
    public Map<String, List<Map<String, Object>>> getRepayPlan(String type, List<String> list) {
        return null;
    }

    /**
     * 保存额度申请异步返回的批次信息
     * 
     * @param dto
     * @return
     */
    public void saveQuotaReturn(QuotaReturnDto dto) {

    }

    /**
     * 合作机构转让批量赎回
     * @Title redeemCreditRight
     * @Description TODO void
     * @author lixinyao
     * @date 2015-1-23-上午11:13:40
     * @update
     * @throws
     */
    public RedeemResultDto redeemCreditRight(RedeemParamDto redeemParamDto) {
    	filterCreditDetailUtil.filterCreditDetail(redeemParamDto);
    	
        return creditPoolIFImpl.redeemCreditRight(redeemParamDto);
    }

    /**
     * 根据合同号获取还款计划
     * 
     * @Title getcreditRepayPlan
     */
    public CreditRepayPlanQueryResultDto getCreditRepayPlan(CreditRepayPlanQueryDto queryDto) {
        return creditPoolIFImpl.getCreditRepayPlan(queryDto);
    }

    /**
     * 查询指定日期债权价值
     * 
     * @param creditValueCalculateDto 贷款、债权
     * @return
     */
    public List<CreditValueCalculateResultDto> getCreditValue(CreditValueCalculateDto creditValueCalculateDto) {
    	filterCreditDetailUtil.filterCreditDetail(creditValueCalculateDto);
    	
        return creditPoolIFImpl.getCreditValue(creditValueCalculateDto);
    }

    public CoreStatusResponse queryCoreStatus(@Valid String date) {
        return loanIFImpl.queryCoreStatus(date);
    }

    /**
     * @description 获取贷前系统贷款的影像信息
     * @author shengzhoutao
     * @param contractNo 合同号
     * @return List<ImgUrl>
     */
    public List<ImgUrl> getBefLoanImgUrl(String contractNo) {
        return loanIFImpl.getBefLoanImgUrl(contractNo);
    }

    /**
     * @description 获取贷前系统贷款的影像信息
     * @author shengzhoutao
     * @param contractNo 合同号
     * @return LoanData
     */
    public LoanData getBefLoanInfo(String contractNo) {
        return loanIFImpl.getBefLoanInfo(contractNo);
    }

    /**
     * @description 获取贷前系统借款人相关方面的信息
     * @author shengzhoutao
     * @param contractNo 合同号
     * @return Response8003DTO
     */
    public Response8003DTO getBorrowersResult(String contractNo){
    	return loanIFImpl.getBorrowersResult(contractNo);
    }
    
    public PublicInfoQueryResult getPublicInfo(PublicInfoQueryDto publicInfoQueryDto) {
        return creditPoolIFImpl.getPublicInfo(publicInfoQueryDto);
    }
    
    public Response4029DTO sendSRCreditsToCore(Request4029DTO request) {
        return creditPoolIFImpl.sendSRCreditsToCore(request);
    }
    
    public Response4036DTO cancelSRCreditsToCore(Request4036DTO request) {
    	return creditPoolIFImpl.cancelSRCreditsToCore(request);
    }

    /**
     * 贷款转出批量回购(发送给核心系统)
     * @param redeemParamDto 回购参数信息
     * @return RedeemResultDto
     * @author yanjingying
     * @date 2015-12-11-下午16:41:23
     * @update
     */
	public RedeemResultDto sendLoanTransferBatchRedeemToCore(RedeemParamDto redeemParamDto) throws Exception{
		return loanIFImpl.sendLoanTransferBatchRedeemToCore(redeemParamDto);
	}
    /**
     * 受让赎回功能接口
     * @Title sendSrCreditorBatchRedeemToCore
     * @Description TODO
     * @param redeemParamDto
     * @return
     * @throws Exception 
     * RedeemResultDto 
     * @author lizhiqiang
     * @date 2016-2-23-下午4:58:40
     * @update 
     * @throws
     */
	public RedeemResultDto sendSrCreditorBatchRedeemToCore(RedeemParamDto redeemParamDto) throws Exception{
		return creditPoolIFImpl.sendSrCreditorBatchRedeemToCore(redeemParamDto);
	}
	/**
	 * 
	 * @Title sendZrCreditRedeemSettle
	 * @Description TODO
	 * @param publicSettleParamDto
	 * @return
	 * @throws Exception 
	 * PublicSettleResultDto 
	 * @author lizhiqiang
	 * @date 2016-4-18-下午4:45:45
	 * @update 
	 * @throws
	 */
	public PublicSettleResultDto sendZrCreditRedeemSettle(PublicSettleParamDto publicSettleParamDto) throws Exception{
		return creditPoolIFImpl.sendZrCreditRedeemSettle(publicSettleParamDto);
	}

	/**
	 * 发送结算申请
	 * @author zhangmi
	 * @date 2016-8-19 下午2:22:16
	 * @see com.jy.modules.cims.interact.ICInteract#sendSettleApply(com.jy.modules.cims.data.dto.credit.PublicSettleParamDto)
	 */
	public PublicSettleResultDto sendSettleApply(PublicSettleParamDto publicSettleParamDto) throws Exception {
		return creditPoolIFImpl.sendSettleApply(publicSettleParamDto);
	}

	/**
	 * 二次购买-接口
	 * @author zhangmi
	 * @date 2016-8-19 下午2:32:09
	 * @see com.jy.modules.cims.interact.ICInteract#sendTwoCreditBuy(com.jy.modules.cims.data.dto.credit.PublicSettleParamDto)
	 */
	public PublicSettleResultDto sendTwoCreditBuy(PublicSettleParamDto publicSettleParamDto) throws Exception {
		return creditPoolIFImpl.sendTwoCreditBuy(publicSettleParamDto);
	}

	/**
	 * 虚拟月还挂账
	 * @author zhangmi
	 * @date 2016-8-19 下午2:32:13
	 * @see com.jy.modules.cims.interact.ICInteract#sendVRMonthGz(com.jy.modules.cims.data.dto.credit.PublicSettleParamDto)
	 */
	public PublicSettleResultDto sendVRMonthGz(PublicSettleParamDto publicSettleParamDto) {
		return creditPoolIFImpl.sendVRMonthGz(publicSettleParamDto);
	}

	/**
	 * 二次购买-撤销
	 * @author zhangmi
	 * @date 2016-8-19 下午2:32:16
	 * @see com.jy.modules.cims.interact.ICInteract#sendTwoCreditBuyReturn(com.jy.modules.cims.data.dto.credit.PublicSettleParamDto)
	 */
	public PublicSettleResultDto sendTwoCreditBuyReturn(PublicSettleParamDto publicSettleParamDto) {
		return creditPoolIFImpl.sendTwoCreditBuyReturn(publicSettleParamDto);
	}

	/**
	 * 月还现金结算
	 * @author zhangmi
	 * @date 2016-8-19 下午2:32:19
	 * @see com.jy.modules.cims.interact.ICInteract#sendMonthCashRepay(com.jy.modules.cims.data.dto.credit.PublicSettleParamDto)
	 */
	public PublicSettleResultDto sendMonthCashRepay(PublicSettleParamDto publicSettleParamDto) throws Exception {
		return creditPoolIFImpl.sendMonthCashRepay(publicSettleParamDto);
	}

	/**
	 * 结清债权现金结算
	 * @author zhangmi
	 * @date 2016-8-19 下午2:32:23
	 * @see com.jy.modules.cims.interact.ICInteract#sendCreditCashSettle(com.jy.modules.cims.data.dto.credit.PublicSettleParamDto)
	 */
	public PublicSettleResultDto sendCreditCashSettle(PublicSettleParamDto publicSettleParamDto) throws Exception {
		return creditPoolIFImpl.sendCreditCashSettle(publicSettleParamDto);
	}
	
    /**
     * 发送贷款回购结算申请
     * @Title sendLoanBuybackSettleApply
     * @Description 回购贷款、赎回债权一起发送进行结算
     * @param publicSettleParamDto 公共结算参数
     * @return PublicSettleResultDto  公共结算结果
     * @throws Exception
     * @author yanjingying
     * @date 2016-8-19 10:00:00
     */
	public PublicSettleResultDto sendLoanBuybackSettleApply(PublicSettleParamDto publicSettleParamDto) throws Exception{
		return loanSettleIFImpl.sendLoanBuybackSettleApply(publicSettleParamDto);
	}
	/**
	 * 贷款转出结算申请接口调用
	 * @Title sendLoanDealSettleApply
	 * @Description TODO
	 * @param loanDealSettleDto
	 * @return
	 * @throws Exception 
	 * PublicSettleResultDto 
	 * @author lizhiqiang
	 * @date 2016-8-26-上午9:19:57
	 * @update 
	 * @throws
	 */
	public PublicSettleResultDto sendLoanDealSettleApply(LoanDealSettleDto loanDealSettleDto) throws Exception{
		return loanSettleIFImpl.sendLoanDealSettleApply(loanDealSettleDto);
	}
	
}
